1. Field of the Invention
The present invention relates generally to memory management in a data processing system and specifically to a memory management scheme that is adapted to address the problem of debugging heap.
2. Description of the Related Art
Programs often wish to dynamically allocate memory from a shared dynamic memory pool. This allows programs to scale their memory usage to runtime environments. The memory pool is a dynamic pool because the amount of memory a program needs does not need to be known until runtime. Thus, memory is allocated during runtime, or “dynamically.” This shared dynamic pool of memory is often referred to as “heap” or sometimes as “shared heap.”
The opposite of dynamic memory is static memory. For static memory, a program may say it always uses a fixed amount of memory. That is simpler, but it does not allow the program to use additional memory.
Heap is commonly used in single threaded applications. In single threaded applications, heap memory is shared among components of the application. An application can be very large and have unrelated components that are allocating memory from a single pool. The management of the heap is done by either the applications themselves, allocating and de-allocating memory as required, or by the operating system or other data processing system programs.
The malloc( ) application program interface (API) is an example of a memory allocator. APIs are a set of routines that an application uses to request and carry out lower-level services performed by a computer's operating system. Also, APIs may be a set of calling conventions in programming that define how a service is invoked through the application.
The memory returned from malloc( ) is often shared among multiple software components. Malloc( ) is primarily a C library routine that returns number bytes and the address for those bytes to the calling routine. The malloc( ) API takes a number-of-bytes as an input parameter. This allows programs to wait until they know input parameters to request the memory they need.
The free( ) API is used to free the memory allocated by a malloc( ) call. Other languages use memory allocators that work in the same manner. For example, in the Advanced Interactive Executive (AIX) operating system, the kernel API xmalloc( ) is used to allocate memory and xmfree( ) is used to free the memory.
Bugs occur when the programs still use the memory stored in a location even though a free( ) API has occurred. Other types of bugs include using more memory than was allocated and failing to initialize memory. These bugs can cause the previous data to corrupt or overwrite the data that is supposed to be placed into the memory currently.
When heap corruption occurs in dynamically allocated memory, the results can be unpredictable and difficult to diagnose.